﻿using System;
using System.Collections.Generic;
using System.Text;
using VietKinsNutrition.Data;
using System.Windows.Forms;
using System.Data;
using DevExpress.Utils.Serializing;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.BandedGrid;
using DevExpress.XtraEditors;

namespace VietKinsNutrition.Bussiness
{
    public class ClsTblDm_ThanhphandingduongcuathucanBLL
    {
        ClsTblDm_ThanhphandinhduongthucanDAL ClsTblDm_Thanhphandinhduongthucan_dal = new ClsTblDm_ThanhphandinhduongthucanDAL();
        private int _id;
        private string _name;
        DataView dv;

        public string Name
        {
            set { _name = value; }
        }
        public int ID
        {
            set { _id = value; }
        }

        public void DataGridView_Click(AdvBandedGridView grid)
        {
            if (grid.GetFocusedRowCellValue("Id").ToString() != "")
            {
                _id = int.Parse(grid.GetFocusedRowCellValue("Id").ToString());
                _name = grid.GetFocusedRowCellValue("Tenthucan").ToString();
            }
        }
        public void FillComboBox(DevExpress.XtraEditors.LookUpEdit lue)
        {
            lue.Properties.DataSource = ClsTblDm_Nhomthucpham_ThucanDAL.GetTable();
            lue.Properties.DisplayMember = "Tennhom";
            lue.Properties.ValueMember = "Id";
            lue.Properties.PopulateColumns();
            lue.Properties.Columns["Id"].Visible = false;
            lue.Properties.Columns["STT"].Width = 15;
            lue.Properties.NullText = "Tất cả thực phẩm";
        }
        public void Bind_Grid(GridControl gridControl, string Tenthucan, int NhomthucphamId)
        {
            gridControl.DataSource = ClsTblDm_Thanhphandinhduongthucan_dal.Thanhphandinhduong_ByNhomId_Tenthucan(Tenthucan, NhomthucphamId);
        }
        public void Bind_Grid(GridControl gridControl, string Tenthucan)
        {
            gridControl.DataSource = ClsTblDm_Thanhphandinhduongthucan_dal.Thanhphandinhduong_ByNhomId_Tenthucan(Tenthucan);
        }
        public void LoadDataGridView(GridControl gridControl, int Id)
        {
            gridControl.DataSource = ClsTblDm_Thanhphandinhduongthucan_dal.GetTable(Id);
        }
        public void LoadDataGridView(GridControl gridControl)
        {
            //dv = new DataView(ClsTblDm_Thanhphandinhduongthucan_dal.GetTable());
            gridControl.DataSource = ClsTblDm_Thanhphandinhduongthucan_dal.GetTable();
        }
        public DataTable Thanhphandinhduong_ByNhomId_Tenthucan(int NhomthucphamId)
        {
            return ClsTblDm_Thanhphandinhduongthucan_dal.Thanhphandinhduong_ByNhomId_Tenthucan(NhomthucphamId);
        }
        public void Delete()
        {
            if (_name == null)
            { XtraMessageBox.Show("Phải chọn danh mục để  xóa ", "Chú ý"); }
            else
            {
                if (XtraMessageBox.Show("Bạn có chắc  chắn muốn xóa " + _name + " không ?", "Chú ý", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    ClsTblDm_Thanhphandinhduongthucan_dal.Delete("@IdDinhDuong", _id);
                }
            }
        }
    }
}
